<template>
  <div>
    <h1>分类列表</h1>
    <el-table :data="getListInfo">
      <el-table-column label="所属分类" prop="parents.name"></el-table-column>
      <el-table-column label="名称" prop="name"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row._id)"
            >编辑</el-button
          >
          <el-button size="mini" type="danger" @click="deleteInfo(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 编辑对话框 -->
    <el-dialog
      title="提示"
      :visible.sync="editDialogVisible"
      width="30%"
      center
    >
      <el-form label-width="80px">
        <el-form-item label="所属分类">
          <el-select v-model="editInfo.parents" clearable>
            <el-option
              v-for="item in getListInfo"
              :key="item._id"
              :label="item.name"
              :value="item._id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="名称">
          <el-input v-model="editInfo.name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="updateFormInfo">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { CATEGORY } from '@/utils/const'

export default {
  mixins: [commonMixin],
  created () {
    this.getList(CATEGORY)
  },
  methods: {
    // 点击编辑按钮触发的事件
    handleEdit (id) {
      this.edit(CATEGORY, id)
    },
    // 点击编辑->确定按钮触发的事件
    updateFormInfo () {
      this.updateInfo(CATEGORY)
    },
    // 点击删除按钮触发的事件
    deleteInfo (rowdata) {
      this.del(CATEGORY, rowdata)
    }
  }
}
</script>

<style scoped>
</style>